import numpy as np
import json
import datetime
from pyecharts.charts import Line
from pyecharts import options as opts

from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.faker import Faker

# 读原始数据文件
today = datetime.date.today().strftime('%Y%m%d')   # 20200404
# 20200404_chinaData.json
datafile = 'data/' + today + '_chinaData.json'
with open(datafile, 'r', encoding='utf-8') as file:
    json_array = json.loads(file.read())

# 分析全国实时确诊数据：'confirmedCount'字段
china_data = []
for province in json_array:
    # 这边地图不能带有最后一个字省或者市之类的，不然画不了图
    china_data.append((province['provinceShortName'], province['confirmedCount']))  # (省的名字，确诊人数)
china_data = sorted(china_data, key=lambda x: x[1], reverse=True)  # key 排序的关键字 reverse=True,表示降序，反之升序
print(china_data)

# 全国疫情饼状图

# data(省的名字，确诊人数)
labels = [data[0] for data in china_data]
counts = [data[1] for data in china_data]

